package org.his.controller.binglidangan;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.his.dao.CaseInfoDao;
import org.his.pojo.binglidangan.CaseInfo;
import org.his.pojo.liucheng.Reserve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/case")
public class CaseInfoController {

    @Autowired
    private CaseInfoDao caseInfoDao;

    @RequestMapping("/index")
    public String index() throws Exception{
        return "binglidangan/index";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,String reserveName) throws Exception{
        Map<String, Object> map = new HashMap<>();
        Page<CaseInfo> pager = PageHelper.startPage(page, limit);

        CaseInfo caseInfo = new CaseInfo();

        if (reserveName != null && reserveName != ""){
            Reserve reserve = new Reserve();
            reserve.setReserveName(reserveName);
            caseInfo.setMemberCaseNo(reserve);
        }


        map.put("data", caseInfoDao.getList(caseInfo));
        map.put("count", pager.getTotal());
        map.put("code", 0);
        map.put("msg", null);
        return map;
    }

    @RequestMapping("/batchDelete")
    @ResponseBody
    public Map<String,Object> batchDelete(Integer ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        caseInfoDao.delete(ids);
        return map;
    }


    @RequestMapping("/zhenduanluru")
    @ResponseBody
    public Map<String,Object> zhenduanluru (@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) throws Exception{
        Map<String, Object> map = new HashMap<>();
        Page<CaseInfo> pager = PageHelper.startPage(page, limit);
        map.put("data", caseInfoDao.zhenduanluru());
        map.put("count", pager.getTotal());
        map.put("code", 0);
        map.put("msg", null);
        return map;
    }

    @RequestMapping("/zhenduanIndex")
    public String zhenduanIndex() throws Exception{
        return "binglidangan/zhenduanIndex";
    }
    @RequestMapping("/xiangqing")
    public String xiangqing() throws Exception{
        return "modular/yisheng/xiangqing";
    }

    @RequestMapping("/getcaseinfo")
    @ResponseBody
    public CaseInfo getcaseinfo(Integer reserveId) throws Exception{
        return  caseInfoDao.get(reserveId);
    }


}
